LoadText("TextObject","variable$")
LoadText("TextObject","path")
LoadText("TextObject","<List>")
LoadText("TextObject","<List>Number")
LoadText("variable$","path")
LoadText("variable$","<List>Number")
Important command for string variables.
The load text loads a string, a file from the path, a list or a single item from the list into the text object (Text, Paragraph text, Input Edit)It also loads a file from the path and a list (or item from the list) into the string variable.
Changed in 4.9.5:
If the string
variable used as a first
parameter will point to an object (text, button, ...) in your project, then
the LoadText function will replace the text
in this object i.e. it will not load the contents of the second parameter
into the string variable as previously. This will allow you to
dynamically replace the text in a serie of text objects or buttons by simple
For..Next loop.
Let's imagine you have an array of 100 buttons and you have to change the title of all of them. Previously you need to use the LoadText function for each of them..it means 100 lines of almost the same code. But now you can use simple For..Next loop like here:
For i=1 To 100
var$='TextBTN'+CHAR(i)
LoadText("var$","var$")
Next i
The list is the Song list
This command can load a text into text object (Paragraph Text, Text, Text Button) from String variable or file. The command decides itself if the text in variable is just a plain text or it points to the file. It can expand the string to full path as well.
C$='<SrcDir>\MyFile.txt'
LoadText("Object","C$")
*** load a text file from the path directly to the Object.
C$='Whatever text'
LoadText("Object","C$")
*** display just the text directly in the Object.
In both cases (direct text or variable), the command will
guess if the argument is a pointer to a file or just simple
text.
If the file doesn't exist the LoadText will display it as a
string.
Direct format
The previous format let MMB guess what we like to do (read
text from file in string variable or display the string
variable as a text). If you (or MMB) are in doubt, use the
direct command before variable:
STRING:variable or FILE:variable
Example:
path$ = '<SrcDir>\myfile.txt'
LoadText("Text","FILE:path$") will load the text from a file
specified in the path$
LoadText("Text","STRING:path$") will load the text from the
path$ directly - in our case the Text will show the
<SrcDir>\myfile.txt
Tip: If you want to split a long string into the multiple lines, then use \n parameter in the string.
Example:
LongStr$ = 'This
is a very long string \nsplitted into two rows'
LoadText("Text","LongStr$")
See more about LoadText here.